package com.gitee.center.test.flow.form;

import com.gitee.center.CenterServer;
import com.gitee.center.runtime.Center;
import com.gitee.center.test.Steps;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;
@Slf4j
@SpringBootTest(classes = CenterServer.class)
@RunWith(SpringRunner.class)
public class StartProcessInstance {

    @Autowired
    private StartProcessInstanceStepsExec startProcessInstanceStepsExec;

    @Test
    public void start() {
        //封装ProcessInstance
        ProcessInstance processInstance = new ExtProcessInstance("KAS");
        List<String> steps = Center.findAbility(FlowDecideStepsAbility.class).decideSteps(processInstance, Steps.StartProcessInstance.Activity);
        if (steps != null && !steps.isEmpty()) {
            // 通过步骤编排的模板方法执行每一个步骤，其中涉及到：步骤回滚，步骤重新编排
            startProcessInstanceStepsExec.execute(Steps.StartProcessInstance.Activity, steps, processInstance);
        }
    }

}
